using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace MyToDo.ViewModels
{
    public class CheckComboBoxDemoViewModel : INotifyPropertyChanged
    {
        // 水果集合
        private ObservableCollection<string> fruits;
        public ObservableCollection<string> Fruits
        {
            get { return fruits; }
            set { fruits = value; OnPropertyChanged(); }
        }

        // 选中的水果
        private ObservableCollection<object> selectedFruits;
        public ObservableCollection<object> SelectedFruits
        {
            get { return selectedFruits; }
            set { selectedFruits = value; OnPropertyChanged(); }
        }

        // 城市集合
        private ObservableCollection<string> cities;
        public ObservableCollection<string> Cities
        {
            get { return cities; }
            set { cities = value; OnPropertyChanged(); }
        }

        // 选中的城市
        private ObservableCollection<object> selectedCities;
        public ObservableCollection<object> SelectedCities
        {
            get { return selectedCities; }
            set { selectedCities = value; OnPropertyChanged(); }
        }

        // 编程语言集合
        private ObservableCollection<string> languages;
        public ObservableCollection<string> Languages
        {
            get { return languages; }
            set { languages = value; OnPropertyChanged(); }
        }

        // 选中的编程语言
        private ObservableCollection<object> selectedLanguages;
        public ObservableCollection<object> SelectedLanguages
        {
            get { return selectedLanguages; }
            set { selectedLanguages = value; OnPropertyChanged(); }
        }

        // 颜色集合
        private ObservableCollection<string> colors;
        public ObservableCollection<string> Colors
        {
            get { return colors; }
            set { colors = value; OnPropertyChanged(); }
        }

        // 选中的颜色
        private ObservableCollection<object> selectedColors;
        public ObservableCollection<object> SelectedColors
        {
            get { return selectedColors; }
            set { selectedColors = value; OnPropertyChanged(); Console.WriteLine(SelectedColors.Count); }
        }

        public CheckComboBoxDemoViewModel()
        {
            // 初始化数据
            InitializeData();
        }

        private void InitializeData()
        {
            // 初始化水果数据
            Fruits = new ObservableCollection<string>
            {
                "苹果",
                "香蕉",
                "橙子",
                "草莓",
                "葡萄",
                "西瓜",
                "梨"
            };
            SelectedFruits = new ObservableCollection<object> { "苹果", "香蕉" };

            // 初始化城市数据
            Cities = new ObservableCollection<string>
            {
                "北京",
                "上海",
                "广州",
                "深圳",
                "杭州",
                "成都",
                "武汉",
                "南京"
            };
            SelectedCities = new ObservableCollection<object> { "北京", "上海" };

            // 初始化编程语言数据
            Languages = new ObservableCollection<string>
            {
                "C#",
                "Java",
                "Python",
                "JavaScript",
                "TypeScript",
                "Go",
                "Rust"
            };
            SelectedLanguages = new ObservableCollection<object>();

            // 初始化颜色数据
            Colors = new ObservableCollection<string>
            {
                "红色",
                "蓝色",
                "绿色",
                "黄色",
                "橙色",
                "紫色",
                "黑色",
                "白色",
                "灰色"
            };
            SelectedColors = new ObservableCollection<object> { "红色", "蓝色", "绿色" };
        }

        // 实现INotifyPropertyChanged接口
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}